import json
from fixture.fixture import *
import pytest

def read_json(file):
    with open(file,'r',encoding='utf_8')as f:
        data = json.load(f)
        return [(i['bookname'],i["price"],i["num"],i["buy"],i["booktype"])for i in data]

@pytest.mark.parametrize("bookname,price,num,buy,booktype",read_json(r"C:\Users\34098\PycharmProjects\jiaqi1\lib\data.json"))
def test_add(add_url,bookname,price,num,buy,booktype):
    try:
        data = {"bookname":bookname,
                "price":price,
                "num":num,
                "buy":buy,
                "booktype":booktype}
        req = add_url.post(url='addbook/',status="json",data = data)
        print(req.json())
    except Exception as e:
        print(e)

def test_add_a(add_url):
    try:
        req = add_url.post(url='addbook/')
        print(req.json())
    except Exception as e:
        print(e)

def test_delete(delete_url):
    try:
        req = delete_url.delete(url="deletebook/1")
        print(req)
    except Exception as e:
        print(e)

def test_delete_a(delete_url):
    try:
        req = delete_url.delete(url="deletebook/50")
        print(req)
    except Exception as e:
        print(e)

def test_delete_b(delete_url):
    try:
        req = delete_url.delete(url="deletebook/")
        print(req)
    except Exception as e:
        print(e)

def test_put(delete_url):
    try:
        req = delete_url.delete(url="updatabook/1")
        print(req)
    except Exception as e:
        print(e)

def test_put_a(delete_url):
    try:
        req = delete_url.delete(url="updatabook/1")
        print(req)
    except Exception as e:
        print(e)

def test_put_b(delete_url):
    try:
        req = delete_url.delete(url="updatabook/1")
        print(req)
    except Exception as e:
        print(e)

def test_put_delete(delete_url):
    try:
        delete_url.delete(url="deletebook/1")
        req = delete_url.delete(url="updatabook/1")
        print(req)
    except Exception as e:
        print(e)

